# !/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@author: JHC000abc@gmail.com
@file: base_script.py
@time: 2024/10/31 15:54 
@desc: 

"""
from sdk.utils.util_times import TimeProcess
from sdk.utils.util_compress import ZipProcess
from sdk.temp.temp_supports import IsSolution, DM
from sdk.utils.util_encrypt import EncryptProcess


class BaseScript(IsSolution):
    """

    """

    def __init__(self):
        super().__init__()
        self.desc = "base script"
        self.time = TimeProcess()
        self.zip = ZipProcess()
        self.ep = EncryptProcess()
        DM.callback = None
        self.static_save_path = "static/download"
        self.tmp_upload_path = "tmp/uploads/"
        self.folder.create_folder(self.static_save_path)


    def check_keys(self, data, keys):
        """

        :param data:
        :param keys:
        :return:
        """
        for key in keys:
            if data.get(key) is None:
                raise KeyError(key)
        self.tmp_folder, self.zip_file, self.zip_name = self.make_out()

    def format_folder(self, path):
        """

        :param path:
        :return:
        """
        return path.replace('\\', '/')

    def make_out(self):
        """

        :param path:
        :return:
        """
        tmp_folder = self.format_folder(self.make_out_path(self.static_save_path, [self.desc,self.ep.make_uuid(1)]))

        zip_name = f"result_{self.desc}_{self.time.get_normal_date('%Y-%m-%d_%H-%M-%S')}.zip"
        zip_file = self.format_folder(self.folder.merge_path(
            [self.static_save_path, zip_name]))
        return tmp_folder, zip_file, zip_name
